package com.ftg.learn.chapter09.pattern.factory;

/**
 * @author kangjx
 * @date 2023/1/17
 */
public class CouseFacctory01<T extends AbstractCourse> {

    /**
     * 表示你给一个 AbstractCourse 子类的实例，我帮你给定初始值
     * 不能存在抽象当，抽象不能实例化
     * @param t1
     * @param courseName
     * @param teacherName
     * @param desc
     * @return
     */
    public T getCourse(T t1, String courseName, String teacherName, String desc) {
        t1.setCourseName(courseName);
        t1.setDesc(desc);
        t1.setTeacherName(teacherName);
        return t1;
    }

    public T getCourse(Class<T> t1, String courseName, String teacherName, String desc) {
        try {
            //产生了 AbstractCourse 子类的真实实例
            AbstractCourse ab = t1.newInstance();
            ab.setCourseName(courseName);
            ab.setDesc(desc);
            ab.setTeacherName(teacherName);
            return (T) ab;
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }


}
